package Hot100.Tree;

import java.util.ArrayList;
import java.util.List;

public class isValidBST {
    public static void main(String[] args) {
        int[] value = {5,4,6,-1,-1,3,7};
        BinaryTree binaryTree = new BinaryTree();
        binaryTree.insert(value);
        System.out.println(new isValidBST().isValidBST(binaryTree.root));
    }
    List<Integer> list = new ArrayList<>();
    public boolean isValidBST(TreeNode root) {
        if (root == null)
            return false;
        inorder(root);

        for (int i = 0; i < list.size() - 1; i++) {
            if(list.get(i) > list.get(i+1))
                return false;
        }
        return true;

    }
    public void inorder(TreeNode root){
        if(root == null)
            return;
        inorder(root.left);
        list.add(root.val);
        inorder(root.right);
    }


}
